package com.freak.kotlinfitnessserver.activity

import android.Manifest
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.freak.kotlinfitnessserver.constant.DeviceConstant
import com.freak.kotlinfitnessserver.databinding.ActivityFitnessTypeBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class FitnessTypeActivity : AppCompatActivity() {
    private lateinit var binding: ActivityFitnessTypeBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityFitnessTypeBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.linearLayoutCompatConfigBack.setOnClickListener {
            finish()
        }
        binding.buttonTreadmill.setOnClickListener {
            val intent = Intent()
            intent.putExtra(DeviceConstant.deviceType, DeviceConstant.treadmill)
            intent.setClass(this, BleServerActivity::class.java)
            startActivity(intent)
        }
        binding.buttonIndoorBike.setOnClickListener {
            val intent = Intent()
            intent.putExtra(DeviceConstant.deviceType, DeviceConstant.indoorBike)
            intent.setClass(this, BleServerActivity::class.java)
            startActivity(intent)
        }
        binding.buttonRower.setOnClickListener {
            val intent = Intent()
            intent.putExtra(DeviceConstant.deviceType, DeviceConstant.rower)
            intent.setClass(this, BleServerActivity::class.java)
            startActivity(intent)
        }
        binding.buttonEllipticalMachine.setOnClickListener {
            val intent = Intent()
            intent.putExtra(DeviceConstant.deviceType, DeviceConstant.crossTrainer)
            intent.setClass(this, BleServerActivity::class.java)
            startActivity(intent)
        }
        CoroutineScope(Dispatchers.Main).launch {
            requestPermissions(
                arrayOf(
                    Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.BLUETOOTH_SCAN,
                    Manifest.permission.BLUETOOTH_CONNECT,
                    Manifest.permission.BLUETOOTH_ADVERTISE
                ), 1000
            )
        }
    }
}